home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8121 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: news1.h1.usa.pipeline.com!usenet
  2. From: grantp@usa.pipeline.com(Pete)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: fast copy
  5. Date: 14 Feb 1996 22:51:19 GMT
  6. Organization: Kalevi, Inc.
  7. Message-ID: <4ftp17$go3@news1.usa.pipeline.com>
  8. NNTP-Posting-Host: pipe15.h1.usa.pipeline.com
  9. X-PipeUser: grantp
  10. X-PipeHub: usa.pipeline.com
  11. X-PipeGCOS: (Pete)
  12. X-Newsreader: Pipeline USA v3.3.0
  13.  
  14. On Feb 12, 1996 22:05:49 in article <fast copy>, 'cbenoit@mail.imaginet.fr
  15. (Christophe Benoit)' wrote: 
  16.  
  17.  
  18. >Do you know the best method (run-time performance) to copy a file ? 
  19.  
  20. I assume you mean best in terms of time.   
  21.  
  22. 1.  Open the file in binary mode. 
  23. 2.  Determine its size 
  24. 3.  Allocate a buffer large enough for the entire file. 
  25. 4.  Read it in in one fread. 
  26. 5.  Open output file and fwrite entire buffer in one whoosh. 
  27. 6.  Close both. 
  28.  
  29. You can beat this using assembler, but such gains are usually 
  30. insignificant.  If the file is too large to fit into one buffer, split 
  31. it into as large blocks as possible to reduce the number of 
  32. calls to IO routines. 
  33.  
  34. -- 
  35. Pete Grant 
  36. Kalevi, Inc. 
  37. Software Engineering & development
  38.